package es.deusto.ingenieria.BlWhSquares;

import java.util.Vector;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import es.deusto.ingenieria.is.search.formulation.State;
import es.deusto.ingenieria.is.search.xml.StateXMLReader;

public class EnvironmentXMLReader extends StateXMLReader {
	
	private Vector<String> squares;
	

	public EnvironmentXMLReader(String xmlFile) {
		super(xmlFile);
	}
	
	public State getState() {
		
		if(squares.size()<18){
			for(int i=squares.size();i<18;i++){
				squares.add("nada");
			}
		}
		
		return new BlWhSquaresEnvironment(this.squares, 0);
	}

	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
	
	try{
		if (qName.equals("is:lineofsquares")) {
			
		squares = new Vector<String>();
		}else if (qName.equals("is:white")) {
			this.squares.add("white");
		}else if(qName.equals("is:black")){
			this.squares.add("black");
		}
	} catch (Exception ex) {
		System.out.println(this.getClass().getName() + ".startElement(): " + ex);
	}
		
		
	}
}